package hu.uszeged.inf.stud.prf.todo.bean.task;

import hu.uszeged.inf.stud.prf.todo.dao.task.TaskTypeDAO;
import hu.uszeged.inf.stud.prf.todo.entity.task.TaskType;
import hu.uszeged.inf.stud.prf.todo.entity.user.User;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.inject.Inject;

@ManagedBean
@ViewScoped
public class TaskTypeBean {
	
	@Inject
	private TaskTypeDAO taskTypeDAO;
	
	private Long id;
	
	private TaskType taskType;
	
	public void load() {
		if (null == id) {
			taskType = new TaskType();
		} else {
			taskType = taskTypeDAO.findById(id, false);
		}
	}
	
	public String save(User user) {
		taskType.setUser(user);
		taskTypeDAO.makePersistent(taskType);
		taskTypeDAO.flush();
		return "/content/tasktype/list?faces-redirect=true";
	}
	
	public String remove() {
		taskType.setArchive(true);
		taskTypeDAO.makePersistent(taskType);
		taskTypeDAO.flush();
		return "/content/tasktype/list?faces-redirect=true";
	}
	
	public Long getId() {
		return id;
	}
	
	public void setId(Long id) {
		this.id = id;
	}
	
	public TaskType getTaskType() {
		return taskType;
	}
	
	public void setTaskType(TaskType taskType) {
		this.taskType = taskType;
	}

}
